from django.db import models


# Create your models here.


# 一类
class BookInfo(models.Model):
    """书籍信息"""
    title = models.CharField(max_length=20)
    auhtor = models.CharField(max_length=20)
    year = models.DateField()

    def __str__(self):
        return self.title

    # 通过元类 指定数据库表名
    class Meta:
        db_table = 'BookInfo'


# 多类
class BookCharacter(models.Model):
    """角色"""
    name = models.CharField(max_length=20)
    power = models.CharField(max_length=20)
    gender = models.BooleanField(default=True)  # False = 女 True = 男
    foreignKey = models.ForeignKey(BookInfo, on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    # 通过元类 指定数据库表名
    class Meta:
        db_table = 'BookCharacter'
